﻿Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data

Public Class clsDatos
    ReadOnly Property strConexionString As String
        Get
            'Return "Data Source=fs-intelisis;Initial Catalog=PruebasTI;user id=mgbarboza;password=sqlintelisis"
            'Return "Data Source=fs-intelisis;Initial Catalog=PruebasTI;user id=sa;password=$43VacAdminSQL"
            'Return "Data Source=192.168.1.11;Initial Catalog=Intelisis;user id=Desarrollo;password=K33v$2"
            Return "Data Source=192.168.1.11;Initial Catalog=Intelisis;user id=sa;password=$43VacAdminSQL"

        End Get

    End Property

    Function GetDatos(ByVal strSelect As String) As DataTable

        Try
            Dim conConexion As New SqlConnection(strConexionString)
            Dim da As New SqlDataAdapter(strSelect, conConexion)
            Dim ds As New DataSet

            da.Fill(ds)

            Return ds.Tables(0)

        Catch ex As Exception
            Throw ex

        End Try

    End Function

    Function GetRegistro(ByVal strSelect As String) As SqlDataReader
        Try

            Dim conConexion As New SqlConnection(strConexionString)
            Dim cmdCommando As New SqlCommand(strSelect, conConexion)
            Dim rdRegistro As SqlDataReader

            conConexion.Open()

            rdRegistro = cmdCommando.ExecuteReader()

            Return rdRegistro
        Catch ex As Exception
            Throw ex

        End Try

    End Function

    Function Do_ExecuteNonQuery(ByVal strSQL As String) As Integer

        Try
            Dim conConexion As New SqlConnection(strConexionString)
            Dim cmdComando As New SqlCommand(strSQL, conConexion)

            conConexion.Open()

            Return cmdComando.ExecuteNonQuery

        Catch ex As Exception
            Throw ex
        End Try

    End Function

    Function Get_LastID(ByVal strSQLMAX As String) As Integer
        Try

            Dim conConexion As New SqlConnection(strConexionString)
            Dim cmdCommando As New SqlCommand(strSQLMAX, conConexion)

            conConexion.Open()

            Return cmdCommando.ExecuteScalar

        Catch ex As Exception
            Throw ex

        End Try

    End Function
End Class
